package healththink

class FacilityGroupLink {
    FacilityGroup facilityGroup
    Facility facility

    static constraints = {
    }
    
    static FacilityGroupLink link(FacilityGroup fg, Facility f)
    {
        FacilityGroupLink fgl = 
            FacilityGroupLink.findByFacilityGroupAndFacility(
                fg,
                f
            )
        if (!fgl)
        {
            fgl = new FacilityGroupLink()
            fg?.addToFacilities(fgl)
            f?.addToFacilityGroups(fgl)
            fgl.save()
        }
        return fgl
    }
    
    static void unlink(FacilityGroup fg, Facility f)
    {
        FacilityGroupLink fgl = 
            FacilityGroupLink.findByFacilityGroupAndFacility(
                fg,
                f
            )
        
        if (fgl)
        {
            //fg?.removeFromFacilities(fgl)
            //f?.removeFromFacilitiyGroups(fgl)
            fgl.delete()
        }
        
    }
}
